<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/pub/include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理--<c:choose><c:when test="${empty projectEntity}">添加</c:when><c:otherwise>查看</c:otherwise></c:choose></title>
    <link href="<%=request.getContextPath() %>/css/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.form.js"></script>

    <script  language="javascript" type="text/javascript">
        var   outdescriptionTr = '';
        function mydownload(){

//            alert("地址："+outdescriptionTr);
            if(outdescriptionTr == null || outdescriptionTr ==''){
//                alert('下载地址为空,请上传文件');
            }else{
                location = outdescriptionTr;
            }

        }
        function upload(){
            var url = getRootPath()+"/clazz/upload";


            var mydata = document.getElementById("myfile").files[0];
//            alert('mydata'+mydata);
            formData = new FormData();
            formData.append("myfile", mydata);

            $.ajax({
                url: url,
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                },
                success:function(returndata){

                    if(returndata.data.suc){
                        alert("上传成功");
                        document.getElementById( "myfile").style.display= "none";
                        document.getElementById( "uploadbutton").style.display= "none";
                        document.getElementById( "outdescription").value = returndata.data.message;
                        outdescriptionTr = returndata.data.message;
                        document.getElementById( "download").style.display= "block";

                    }else{
                        alert(returndata.data.message);
                    }
                }
            });
        }


        window.onload=function(){
//设置年份的选择
            var myDate= new Date();
            var startYear=myDate.getFullYear()-10;//起始年份
            var endYear=myDate.getFullYear()+10;//结束年份
            var myYear =document.getElementById('pryear');
            var tyYear = myDate.getFullYear();
            var tyjidu = '1';
            <c:if test="${not empty projectEntity}">
            tyYear = ${projectEntity.pryear} ;
            tyjidu = ${projectEntity.prjidu} ;
            </c:if>
            var tf = 0 ;
            var fd = 0 ;

            for (var i=startYear;i<=endYear;i++)
            {
                myYear.options.add(new Option(i,i));
                if (tyYear == i) {
                    fd = tf;
                }
                tf ++;
            }
//            myYear.options[myYear.options.length-11].selected=1;
            myYear.options[fd].selected=1;

            var myjidu=document.getElementById('prjidu');

            var tff = 0 ;
            var fdd = 0 ;
            for (var j=1;j <= 4;j++)
            {
                myjidu.options.add(new Option(j,j));
                if (tyjidu == j) {
                    fdd = tff;
                }
                tff++;
            }
            myjidu.options[fdd].selected=1;
        }
    </script>

    <script type="text/javascript">
        function check(){
            var url = getRootPath()+"/clazz/addproject?m=doadd";
            var   produceid = $("#produceid").val();
            var   coid = $("#coid").val();
            var   aeid = $("#aeid").val();
            var   pryear = $("#pryear").val();
            var   prjidu = $("#prjidu").val();
//            var   focuscategory = $("#focuscategory").val();
            var   name = $("#name").val();
            var   remark = $("#remark").val();
            var   plannum = $("#plannum").val();
//            var   planprioutnum = $("#planprioutnum").val();
            var   plancomoutnum = $("#plancomoutnum").val();
//            var   taxrate = $("#taxrate").val();
            var   tc = $("#tc").val();
            var   po = $("#po").val();
            var   ponum = $("#ponum").val();
            var   potime = $("#potime").val();
//            var   realprioutnum = $("#realprioutnum").val();
            var   realcomoutnum = $("#realcomoutnum").val();
            var   outdescription = $("#outdescription").val();
            var   billnum = $("#billnum").val();
            var   billtime = $("#billtime").val();
            var   billcode = $("#billcode").val();
            var   rertime = $("#rertime").val();
            var   status = $("#status").val();
            var   id = $("#id").val();
            if(produceid=="0"){
                alert("所属产品不能为空");
                return false;
            }
            if(name==""){
                alert("产品名不能为空");
                return false;
            }
            if(status=="0"){
                alert("项目进度不能为空");
                return false;
            }
            <c:if test="${not empty projectEntity}">
            url = getRootPath()+"/clazz/addproject?m=doedit";
            </c:if>

            var para ={
                'id' :id,
                'produceid':produceid,
                'coid':coid,
                'aeid' :aeid,
                'pryear':pryear,
                'prjidu':prjidu,
//                'focuscategory':focuscategory,
                'name':name,
                'remark' :remark,
                'plannum':plannum,
//                'planprioutnum':planprioutnum,
                'plancomoutnum':plancomoutnum,
//                'taxrate':taxrate,
                'tc':tc,
                'po':po,
                'ponum':ponum,
                'potime' :potime,
//                'realprioutnum':realprioutnum,
                'realcomoutnum':realcomoutnum,
                'outdescription':outdescription,
                'billnum':billnum,
                'billtime':billtime,
                'billcode':billcode,
                'rertime':rertime,
                'status' :status
            }
            $.ajax({
                cache:false,
                type:"POST",
                url: url,
                dataType:"json",
                data:para,
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                },
                success:function(returndata){
                    alert(returndata.data.message);
                    if(returndata.data.suc){
                        window.location.href= getRootPath()+"/clazz/project?m=list";
                    }else{

                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="content">
    <jsp:include page="../pub/top.jsp"></jsp:include>
    <!--头部结束-->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="left" valign="top">
                <jsp:include page="../pub/left_clazz.jsp"></jsp:include>
            </td>
            <td valign="top">
                <div class="right">
                    <%--<form action="<c:url value="/clazz/addproject?m=doadd"/>" method="post" style="margin:0">--%>
                    <table width="80%" border="0" cellpadding="0" cellspacing="1" bgcolor="#d1d5d8">
                        <tr>
                            <td height="28" colspan="2" bgcolor="#c6dbf8" class="biaoti" style="padding:0;">
                                <c:choose>
                                    <c:when test="${empty projectEntity}">添加</c:when>
                                    <c:otherwise>查看</c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>项目时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><select id="pryear" name="pryear" style="width:80px;"></select>年 第<select id="prjidu" name="prjidu" style="width:80px;"></select>季度</td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>项目名：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" name="name" id="name"  style="width:200px;" value="${projectEntity.name}" maxlength="25"/></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>所属产品：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="produceid" name="produceid" style="width:200px;" onchange="changeselect()">
                                    <option value="0">选择所属产品</option>
                                    <c:forEach items="${produceList}" var="produce">
                                        <option value="${produce.id}" ${produce.id==projectEntity.produce.id?'selected=selected':''}><c:out value="${produce.producename}"/></option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>下单人：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="aeid" name="aeid" style="width:200px;" disabled="true">
                                    <option value="${sessionScope.user.id}">${sessionScope.user.username}</option>
                                    <c:if test="${not empty projectEntity}">
                                        <c:forEach items="${aes}" var="ae">
                                            <option value="${ae.id}" ${ae.id==projectEntity.ae.id?'selected=selected':''}><c:out value="${ae.username}"/></option>
                                        </c:forEach>
                                    </c:if>
                                    <%--<c:otherwise>--%>
                                    <%--<option value="${sessionScope.user.id}">${sessionScope.user.username}</option>--%>
                                    <%--</c:otherwise>--%>
                                </select>
                                (不能编辑)
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>项目隶属：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="coid" name="coid" style="width:200px;" onchange="changeselect()">
                                    <option value="0">选择项目隶属人</option>
                                    <c:forEach items="${aes}" var="co">
                                        <option value="${co.id}" ${co.id==projectEntity.co.id?'selected=selected':''}><c:out value="${co.username}"/></option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <%--<tr>--%>
                        <%--<td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>项目所属：</td>--%>
                        <%--<td height="28" bgcolor="#FFFFFF">--%>
                        <%--<select id="focuscategory" name="focuscategory" style="width:200px;" onchange="changeselect()">--%>
                        <%--<option value="0">选择项目所属</option>--%>
                        <%--<c:forEach items="${categorys}" var="category">--%>
                        <%--<option value="${category.code}" ${category.code==projectEntity.focusce.code?'selected=selected':''}><c:out value="${category.value}"/></option>--%>
                        <%--</c:forEach>--%>
                        <%--</select>--%>
                        <%--</td>--%>
                        <%--</tr>--%>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*计划金额(含税)：</span></td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="plannum" id="plannum" value="${projectEntity.plannum}"/></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*计划支出金额(含税)：</span></td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="plancomoutnum" id="plancomoutnum" value="${projectEntity.plancomoutnum}" /></td>
                        </tr>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">计划毛利：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" id="planrate" style="width:200px;" name="planrate" value="${projectEntity.planrate}"  readonly/>(不能编辑)</td>

                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>TC号：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="tc" id="tc" value="${projectEntity.tc}"/></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>PO/合同号：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="po" id="po" value="${projectEntity.po}"/></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">PO/合同时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="potime" id="potime"  placeholder="请选择"    value="${projectEntity.potime}"   readonly/> <input type="button" onClick="jeDate({dateCell:'#potime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间" /></td>
                            <%--<td height="28" bgcolor="#FFFFFF"><input type="text" id="potime" name="potime" value="${projectEntity.potime}" maxlength="20" placeholder="请选择"  readonly/> <p><input type="button" onClick="jeDate({dateCell:'#potime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间"></p></td>--%>
                        </tr>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>PO/合同金额：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text"  style="width:200px;" name="ponum" id="ponum"  value="${projectEntity.ponum}" /></td>
                        </tr>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">备注：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <textarea name="remark"  id="remark" style="width:200px;"><c:out value="${projectEntity.remark}"/></textarea>
                            </td>
                        </tr>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">发票号：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" name="billcode" style="width:200px;" min="1" id="billcode" value="${projectEntity.billcode}"/></td>
                        </tr>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">发票金额(含税)：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" name="billnum" style="width:200px;" min="1" id="billnum" value="${projectEntity.billnum}"/></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">发票时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" id="billtime" name="billtime" value="${projectEntity.billtime}" style="width:200px;" placeholder="请选择"  readonly/> <input type="button" onClick="jeDate({dateCell:'#billtime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间"></td>
                        </tr>


                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">实际支出金额：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" name="realcomoutnum" id="realcomoutnum" style="width:200px;" value="${projectEntity.realcomoutnum}" /></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">支出项说明：</td>
                            <td height="28" bgcolor="#FFFFFF">

                                <%--<input type="file" id="myfile" name="myfile" style="width:200px;" />--%>
                                <%--<input type="button" id="uploadbutton" name="uploadbutton" value="上传" onclick="upload()" />--%>
                                <input type="button" name="download" id="download" value="下载" onclick="mydownload()"/>
                                <input type="hidden" name="outdescription" id="outdescription" style="width:200px;" value="${projectEntity.outdescription}"/>
                            </td>
                        </tr>

                        <%--<tr>--%>
                        <%--<td width="15%" height="28" align="right" bgcolor="#edf1f7">支出项说明：</td>--%>
                        <%--<td height="28" bgcolor="#FFFFFF"><input type="text" name="outdescription" id="outdescription" style="width:200px;" value="${projectEntity.outdescription}" /></td>--%>
                        <%--</tr>--%>

                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">回款时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" id="rertime" style="width:200px;" name="rertime" value="${projectEntity.rertime}"  placeholder="请选择"  readonly/> <input type="button" onClick="jeDate({dateCell:'#rertime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间"></td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">实际毛利：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" id="realrate" style="width:200px;" name="realrate" value="${projectEntity.realrate}"  readonly/>(不能编辑)</td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>项目进度：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="status" name="status" style="width:200px;" onchange="changeselect()">
                                    <option value="0">选择项目进度</option>
                                    <c:forEach items="${status}" var="statu">
                                        <option value="${statu.code}" ${statu.code==projectEntity.statusTypeVO.code?'selected=selected':''}><c:out value="${statu.value}"/></option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                    </table>
                    <div class="anniu">
                        <%--<p><input type="button" value="提交" class="fabu" onclick="check()"/>--%>
                            <%--<c:choose>--%>
                                <%--<c:when test="${empty projectEntity}"><input type="reset" value="重置" class="fabu" /></c:when>--%>
                                <%--<c:otherwise><input type="button" value="返回" class="fabu" onclick="history.back()" /></c:otherwise>--%>
                            <%--</c:choose>--%>
                        <%--</p>--%>
                        <input type="hidden" name="id"  id="id" value="${projectEntity.id}"/>
                    </div>
                    <%--</form>--%>
                </div>
                <br />
                <br />
            </td>
        </tr>
    </table>
    <jsp:include page="../pub/foot.jsp"></jsp:include>
</div>

<script type="text/javascript">
    $(function(){
        outdescriptionTr = $("#outdescription").val();
        $('#aeid').attr('disabled', true);
        $('#planrate').attr('disabled', true);
        $('#realrate').attr('disabled', true);
        var userpermission = ${sessionScope.user.permission.code};
        if( userpermission != 4 )
        {
            $('#realcomoutnum').attr('disabled', true);
            $('#outdescription').attr('disabled', true);
        }

        if( userpermission != 3 )
        {
            $('#rertime').attr('disabled', true);
            $('#billcode').attr('disabled', true);
            $('#billnum').attr('disabled', true);
            $('#billtime').attr('disabled', true);
        }
        if( userpermission != 3 )
        {
            $('#rertime').attr('disabled', true);
            $('#billcode').attr('disabled', true);
            $('#billnum').attr('disabled', true);
            $('#billtime').attr('disabled', true);
        }
        if( userpermission != 2 )
        {
            $('#produceid').attr('disabled', true);
            $('#coid').attr('disabled', true);
            $('#pryear').attr('disabled', true);
            $('#prjidu').attr('disabled', true);
            $('#name').attr('disabled', true);
            $('#remark').attr('disabled', true);
            $('#plannum').attr('disabled', true);
            $('#plancomoutnum').attr('disabled', true);
            $('#po').attr('disabled', true);
            $('#ponum').attr('disabled', true);
            $('#potime').attr('disabled', true);
        }
        if( userpermission != 1 )
        {
            $('#tc').attr('disabled', true);
        }

    });
</script>

</body>
</html>
